<?php
/**
 * Introduction: 会员中心
 * @author: 杨陈鹏
 * @email: wanglong@cdlinglu.com
 */

namespace WeChat\Controller\Member;


use Common\Controller\WeChat\SignController;

class IndexController extends SignController
{


    /**
     * Introduction: 修改会员信息
     * @author: 杨陈鹏
     * @email: wanglong@cdlinglu.com
     */
    public function update()
    {

        $data = I('post.data');

        //可修改的字段
        $fields = [
            'avatar',
            'nicname',
            'username',
            'autograph',
            'sex',
        ];

        foreach ($data as $k => $v)
        {

            if(in_array($k,$fields))
                $datas[$k] = $v;

        }

        $logic = D('Common/Member','Logic');

        outPut($logic::update($datas,self::$uid),true);

    }
    /**
     * Introduction: 会员登录之后修改密码
     * @author: 杨陈鹏
     * @email: wanglong@cdlinglu.com
     */
    public function updatePassword()
    {

        $data = I('post.data');

        $logic = D('Common/Member','Logic');

        outPut($logic::updatePassword($data,self::$uid),true);


    }
    /**
     * Introduction: 获取账户信息
     * @author: 杨陈鹏
     * @email: wanglong@cdlinglu.com
     */
    public function balance()
    {

        $logic = D('Common/Distribution','Logic');

        outPut($logic::bonusTotal(self::$uid));

    }
    /**
     * Introduction: 获取收入明细
     * @author: 杨陈鹏
     * @email: wanglong@cdlinglu.com
     */
    public function incomeList()
    {

        $page = I('post.page',1);

        $nums = I('post.nums',20);

        $logic = D('Common/Distribution','Logic');

        outPut($logic::incomeHistory(self::$uid,$page,$nums));

    }
    /**
     * Introduction: 申请微分销
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function applyDis()
    {

        $data = I('post.data');


        $mobile_code = session('mobile_code_' . $data['mobile']);

        if($data['mobile_code'] != $mobile_code)
            outPut(['code' => 300, 'msg' => '验证码错误']);

        unset($data['mobile_code']);

        if(!preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/',$data['id_card']))
            outPut(['code' => 300, 'msg' => '身份证号码格式错误!']);

        $data['uid'] = self::$uid;

        $logic = D('Common/Member','Logic');

        outPut($logic::applyDis($data));



    }

    /**
     * Introduction: 获取一条微分销申请记录
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function distributionOne()
    {

        $logic = D('Common/Member','Logic');

        outPut($logic::distributionOne(self::$uid));

    }
    /**
     * Introduction: 会员提现
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function withdrawals()
    {

        $data = I('post.data');

        $logic = D('Common/Withdrawals','Logic');

        outPut($logic::create($data,self::$uid));

    }

    /**
     * Introduction: 会员提现记录
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function withdrawalsList()
    {

        $page           = I('post.page',1);
        $nums           = I('post.nums',20);

        $logic          = D('Common/Withdrawals','Logic');

        $where['uid']   = self::$uid;

        outPut($logic::getData($where,'*',$page,$nums));

    }

}